package com.demo.heima;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Test11 {

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            log.debug("sleep...");
            // 睡眠中打断会抛出异常
//            try {
//                Thread.sleep(5000); // wait, join
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
            while (true){
                if (Thread.currentThread().isInterrupted()){
                    log.debug("料理后事...");
                    break;
                }
            }
        },"t1");

        t1.start();
        Thread.sleep(1000);
        log.debug("interrupt");
        t1.interrupt();
        log.debug("打断标记:{}", t1.isInterrupted());
    }
}
